<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <video width="200" height="200" autoplay></video>
  <canvas width="400" height="300"></canvas>
</body>
<script>
  "use strict"; {
    // await navigator.mediaDevices.enumerateDevices(); 获取所有的音频和视频设备
    /* navigator.mediaDevices.enumerateDevices().then(res => {
      console.log(res);
    }).catch(err => {
      console.error(err);
    }); */
    let video = document.querySelector("video");
    let canvas = document.querySelector("canvas");
    const get_devices = async () => { //获取媒体设备
      let cameraStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: false });
      video.srcObject = cameraStream;
    };
    get_devices();
  };
</script>

</html>